﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Admin.master" AutoEventWireup="true"
    CodeFile="GenaretaBarcode.aspx.cs" Inherits="WebTeamplate.Admin_GenaretaBarcode" %>

<%@ Import Namespace="Utility" %>
<%@ Import Namespace="BusinessObject" %>
<%@ Register Assembly="Control" Namespace="PagerControl" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <script src="../Js/BasicFunction.js"></script>

    <script src="../Js/ListView.js"></script>

    <script type="text/javascript" language="javascript">

        function popImg() {
            var w = 900;
            var h = 680;
            var wleft = (screen.width - w) / 2;
            var wtop = (screen.height - h) / 2;
            // IE5 and other old browsers might allow a window that is
            // partially offscreen or wider than the screen. Fix that.
            // (Newer browsers fix this for us, but let's be thorough.)
            if (wleft < 0) {
                w = screen.width;
                wleft = 0;
            }
            if (wtop < 0) {
                h = screen.height;
                wtop = 0;
            }
            var pURL = 'PopupBarCode.aspx';
            //var pURL='map.html';
            pInfo = 'toolbar=1,';
            pInfo += 'location=0,';
            pInfo += 'directories=0,';
            pInfo += 'status=0,';
            pInfo += 'menubar=1,';
            pInfo += 'scrollbars=1,';
            pInfo += 'resizable=1,';
            pInfo += 'width=' + w + 'px,';
            pInfo += 'height=' + h + 'px,';
            pInfo += 'left=' + wleft + ',';
            pInfo += 'top=' + wtop + ',';
            pInfo += 'text-align:center';
            //alert(pInfo);
            window.open(pURL, 'BarCode', pInfo, true);
        }
    </script>

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <table class="lvtBg" border="0" cellpadding="0" cellspacing="1" width="100%">
        <tbody>
            <tr>
                <td align="center">
                    <table class="small" border="0" cellpadding="2" cellspacing="5" width="100%">
                        <tr>
                            <td align="right" style="width: 150px">
                                Tên Kho:
                            </td>
                            <td align="left">
                                <%=kho %>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                Ngày nhập:
                            </td>
                            <td align="left">
                                <%=ConvertValueObject.ParseString(objPhieuNhapHang.NgayNhap) %>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                Người nhập / cập nhật:
                            </td>
                            <td align="left">
                                <%=nguoiNhap %>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <hr noshade="noshade" size="1">
                </td>
            </tr>
            <tr>
                <td>
                    <table class="lvt small" border="0" cellpadding="3" cellspacing="1" width="100%">
                        <!-- Table Headers -->
                        <tbody>
                            <tr>
                                <td class="lvtCol" style="width: 40px;">
                                    <input id="chkCheckAll" checked="checked" name="chkCheckAll" onclick='ChekAll(this.checked)'
                                        type="checkbox">
                                </td>
                                <td class="lvtCol" style="width: 80px;">
                                    Mã mặt hàng
                                </td>
                                 <td class="lvtCol" style="width: 100px;">
                                    Mã phụ tùng
                                </td>
                                <td class="lvtCol" style="width: 240px;">
                                    Tên mặt hàng
                                </td>
                                 <td class="lvtCol" style="width: 100px;">
                                    Xe
                                </td>
                                <td class="lvtCol" style="width: 90px;">
                                    Nước SX
                                </td>
                                <td class="lvtCol" style="width: 120px;">
                                    Hiệu
                                </td>
                                <td class="lvtCol" style="width: 50px;">
                                    Số lượng
                                </td>
                                <td class="lvtCol" style="width: 70px;">
                                    Đơn vị tính
                                </td>
                                <td class="lvtCol" style="width: 100px;">
                                    Giá nội bộ
                                </td>
                                <td class="lvtCol" style="width: 50px;">
                                    Số lượng mã vạch
                                </td>
                            </tr>
                            <!-- Table Contents -->
                            <asp:Repeater ID="rptData" runat="server" OnItemDataBound="rptData_ItemDataBound">
                                <ItemTemplate>
                                    <tr class="lvtColData" onmouseover="this.className='lvtColDataHover'" onmouseout="this.className='lvtColData'"
                                        id="row_89" bgcolor="white">
                                        <td class="repeaterCenterData">
                                            <input type="checkbox" checked="checked" name="chk_<%#Eval("MaMatHang") %>" id="chk_<%#Eval("MaMatHang") %>"
                                                onclick="CheckItem('<%#Eval("MaMatHang") %>',this.checked);" />
                                        </td>
                                        <td class="repeaterLeftData">
                                            <%# Server.HtmlEncode(Eval("MaMatHang").ToString())%>
                                        </td>
                                         <td class="repeaterLeftData">
                                            <%# Server.HtmlEncode(Eval("MaPhuTung").ToString())%>
                                        </td>
                                        <td class="repeaterLeftData">
                                            <%# Server.HtmlEncode(Eval("TenMatHang").ToString())%>
                                        </td>
                                        <td class="repeaterLeftData">
                                            <%#GetXe(Eval("MaXe").ToString())%>
                                        </td>
                                        <td class="repeaterLeftData">
                                            <%# Server.HtmlEncode(Eval("NuocSX").ToString())%>
                                        </td>
                                        <td class="repeaterLeftData">
                                            <%# Server.HtmlEncode(Eval("Hieu").ToString())%>
                                        </td>
                                        <td class="repeaterRightData">
                                            <%#Eval("SoLuongNhap")%>
                                        </td>
                                        <td class="repeaterLeftData">
                                            <%# Server.HtmlEncode(Eval("DonViTinh").ToString())%>
                                        </td>
                                        <td class="repeaterRightData">
                                            <asp:Literal ID="ltrGia" runat="server"></asp:Literal>
                                        </td>
                                        <td class="repeaterRightData">
                                            <input type="text" style="width: 60px;" class="txtNumber" value="<%#Eval("SoLuongNhap") %>"
                                                id="txtSoLuongMaVach_<%#Eval("MaMatHang") %>" />
                                        </td>
                                    </tr>
                                </ItemTemplate>
                            </asp:Repeater>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr class="rowDetail" align="right">
                <td colspan="2" class="dvtCellListInfo" align="center">
                    <asp:UpdatePanel ID="upnExport" runat="server">
                        <ContentTemplate>
                            <table width="100%" cellspacing="0" cellpadding="0" border="0" class="small" align="center">
                                <tr>
                                    <td align="center">
                                        <asp:Button ID="btnExportBarCode" runat="server" Text="Tạo mã vạch" OnClientClick="return CheckData();"
                                            Width="100px" OnClick="btnExportBarCode_Click" CssClass="crmbutton 
small edit" />
<%if (!objPhieuNhapHang.IsCommit)
  { %>
<asp:Button ID="btnEdit" runat="server" Text="Cập nhật" 
                                            Width="80px" OnClick="btnEdit_Click" CssClass="crmbutton 
small edit" />
<%} %>

<asp:Button ID="btnPrint" runat="server" Text="Xem chi tiết" 
                                            Width="80px" OnClick="btnPrint_Click" CssClass="crmbutton 
small edit" />
 <asp:Button ID="btnCancel" runat="server" Text="Bỏ qua" 
                                            Width="80px" OnClick="btnCancel_Click" CssClass="crmbutton 
small edit" />


                                    </td>
                                </tr>
                            </table>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </td>
            </tr>
        </tbody>
    </table>
    <input type="hidden" id="hidListId" runat="server" value="" />
    <input type="hidden" id="hidListIdSelect" runat="server" value="" />
    <input type="hidden" id="hidListSoLuong" runat="server" value="" />

    <script type="text/javascript">

        function CheckData() {
            
            var empty = true;
            var result = '';
            //check data valid
            var arr = new Array();
            var idList = document.getElementById('<%=hidListIdSelect.ClientID %>').value;
            arr = idList.split(';');
            if (arr.length > 0) {
                for (var i = 0; i < arr.length - 1; i++) {
                    if (arr[i].toString() != '') {
                        empty = false;
                        var sl = document.getElementById('txtSoLuongMaVach_' + arr[i].toString());
                        //check so luong valid here
                        result += sl.value + ";";
                    }
                }
            }
            if (empty) {
                alert('Vui lòng chọn mặt hàng để tạo barcode');
                return false;
            }
            document.getElementById('<%=hidListSoLuong.ClientID %>').value=result;
            //Get Data and Insert DB
         //   Admin_GenaretaBarcode.GenerateBarCode(idList, result, GenerateBarCodeResult);
            return true;
        }       
        function OpenPopUpBarCode() {
            popImg();
        }
        function CheckItem(id, status) {

            var idSelect = document.getElementById('<%=hidListIdSelect.ClientID %>').value;
            if (status) {
                idSelect += id + ';';
            }
            else idSelect = idSelect.replace(id + ';', '');
            if (idSelect.length == document.getElementById('<%=hidListId.ClientID %>').value.length) {
                document.getElementById('chkCheckAll').checked = true;
            }
            else
                document.getElementById('chkCheckAll').checked = false;
            document.getElementById('<%=hidListIdSelect.ClientID %>').value = idSelect;
        }
        function ChekAll(status) {

            var id = document.getElementById('<%=hidListId.ClientID %>').value;
            var arr = new Array();
            arr = id.split(';');
            if (arr.length > 0) {
                for (var i = 0; i < arr.length; i++) {
                    if (document.getElementById('chk_' + arr[i].toString())) {
                        document.getElementById('chk_' + arr[i].toString()).checked = status;

                    }
                }

            }
            if (status) {
                document.getElementById('<%=hidListIdSelect.ClientID %>').value = id;
            }
            else document.getElementById('<%=hidListIdSelect.ClientID %>').value = '';
        }        
       
    </script>

</asp:Content>
